package main

import (
	"fmt"
	"strconv"
)

func main() {
	n := 19
	fmt.Println(isHappy(n))
}

func isHappy(n int) bool {
	m := make(map[int]int)
	t := 0
	for {
		if n == 1 {
			return true
		}

		v := strconv.Itoa(n)

		if v, ok := m[n]; ok && v > 1 {
			return false
		}

		t = 0
		for i := 0; i < len(v); i++ {
			ti, _ := (strconv.Atoi(string(v[i])))
			t += ti * ti
		}

		n = t
		m[n] = m[n] + 1
	}
}
